import { isFunction, isNull, isObject, isUndefined } from 'lodash-es';

export { isClient, isWindow } from '@vueuse/core';
export { isVNode } from 'vue';

export function isUrl (path: string): boolean {
  const reg =
    /^(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?(\/#\/)?(?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
  return reg.test(path);
}

export const isDef = <T = unknown> (val?: T): val is T => !isUndefined(val);

export const isNullOrUndefined = <T = unknown> (val?: T): val is T => isUndefined(val) || isNull(val);

export const inBrowser = typeof window !== 'undefined';

export const isPromise = <T = any> (val: unknown): val is Promise<T> =>
  // @ts-ignore
  isObject(val) && isFunction(val.then) && isFunction(val.catch);

export const isElement = (e: unknown): e is Element => {
  if (typeof Element === 'undefined') return false;
  return e instanceof Element;
};

export const isKorean = (text: string) =>
  /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi.test(text);

export const isLeaf = (el: HTMLElement) => !el.getAttribute('aria-owns');

export {
  isArray,
  isString,
  isNull,
  isEmpty,
  isNumber,
  isBoolean,
  isEqual,
  isUndefined,
  isObject,
  isPlainObject,
  isFunction
} from 'lodash-es';

